package org.example;

public class Test2 {
    //leetcode 有效的数独
    //https://leetcode.cn/problems/valid-sudoku/description/?envType=study-plan-v2&envId=top-interview-150
    public boolean isValidSudoku(char[][] board) {
        boolean[][] vis1 = new boolean[9][10]; //行
        boolean[][] vis2 = new boolean[9][10]; //列
        boolean[][] vis3 = new boolean[9][10]; //矩阵
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[0].length; j++) {
                if (board[i][j] != '.') {
                    int tmp = board[i][j] - '0';
                    if (vis1[i][tmp] || vis2[j][tmp] || vis3[i/3*3+j/3][tmp]) return false;
                    vis1[i][tmp] = vis2[j][tmp] = vis3[i/3*3+j/3][tmp] = true;
                }
            }
        }
        return true;
    }
}
